<!DOCTYPE html>
<html  lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>
        用户信息管理
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" th:href="@{/css/x-admin.css}" media="all">
</head>
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>用户列表</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"  href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body" >
    <blockquote class="layui-elem-quote news_search" style="padding: 2px;">
        <div class="layui-row">
            <form class="layui-form layui-col-md12 x-so" id="complain_search">
                用户姓名:
                <div class="layui-input-inline">
                    <input type="text" name="userName" id="userName"
                           placeholder="请输入用户姓名" autocomplete="off" class="layui-input">
                </div>
                邮箱:
                <div class="layui-input-inline">
                    <input type="text" name="email" id="email"
                           placeholder="请输入邮箱号" autocomplete="off" class="layui-input">
                </div>
                电话:
                <div class="layui-input-inline">
                    <input type="text" name="phone" id="phone"
                           placeholder="请输电话" autocomplete="off" class="layui-input">
                </div>
                <button id="search" class="layui-btn" lay-submit
                        lay-filter="provinceSearch">
                    <i class="layui-icon">&#xe615;</i>
                </button>
            </form>
        </div>
    </blockquote>
    <xblock ><button class="layui-btn" onclick="member_add('添加用户','/javayh/adduser','500','300')"><i class="layui-icon">&#xe608;</i>添加</button><span class="x-right" style="line-height:40px">总 [[${pageInfo.total } ]]条记录</span></xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th>用户名</th>
            <th>注册日期</th>
            <th>邮箱</th>
            <th>电话</th>
            <th>状态</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody id="x-link">
        <tr  th:each="user:${pageInfo.list}">
            <td class="center" th:text="${user.userName}"></td>
            <td class="center">[[${#dates.format(user.createDate, 'yyyy-MM-dd')}]]</td>
            <td class="center">
                <span class="center">[[${user.email}]]</span>
            </td>
            <td class="center" th:text="${user.phone}" ></td>
            <td class="center">
                <span class="layui-btn layui-btn-normal">[[${user.active}]]</span>
            </td>

            <td class="center">
                <a class="layui-btn layui-btn-danger" href="javascript:;" onclick="commemt_del(this,$(this).parents('tr').find('td')[6].innerHTML)" >
                    <i class="layui-icon">&#xe640;</i>
                    Delete
                </a>
            </td>
            <td class="center" th:text="${user.id}" style="display:none"></td>
        </tr>
        </tbody>
    </table>

    <div id="page"></div>

</div>

<!--=====================================javascript================================= -->
<script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
<script th:src="@{/js/x-layui.js}" charset="utf-8"></script>
<script   type="text/javascript" th:inline="javascript" >

    layui.use(['element','laypage','layer','form'], function(){
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        laydate = layui.laydate;//日期插件
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层
        form = layui.form();//弹出层
        //  1)分页插件
        //以上模块根据需要引入
        laypage({
            cont: 'page'
            ,pages: [[${pageInfo.pages }]]
            ,curr: [[${pageInfo.pageNum }]]
            ,first: '首页'
            ,last: '尾页'
            ,prev: '<em><</em>'
            ,next: '<em>></em>'
            ,jump : function(obj, first){
                if (!first) {
                    var pn=obj.curr;
                    window.location.href="/javayh/alluser_admin?pn="+pn;//跳转链接
                }
            }
        });
    })

    //==================================================================================//
    /* 添加新用户（初始添加不带任何权限） */
    function member_add(title,url,w,h){
        x_admin_show(title,url,w,h);
    }

    /* 用户添加完成后，通过update更新具体权限 */
    //批量删除提交
    function delAll () {
        layer.confirm('确认要删除吗？',function(index){

            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
        });
    }

    var basePath = [[${#httpServletRequest.getScheme() + "://" + #httpServletRequest.getServerName() + ":" + #httpServletRequest.getServerPort() + #httpServletRequest.getContextPath()}]];

    /* 单用户删除模块  */
    function commemt_del(obj,id){
        //alert(id+basePath);
        layer.confirm('确认要删除吗？',function(index){
            //发异步删除数据
            $.ajax({
                url: basePath+'/javayh/delete?id=' +id,
                type: 'DELETE',
                dataType: 'json',
                async: false,
                success:function(result){
                    console.log(result);
                    if(result.code==1){
                        $(obj).parents("tr").remove();
                        location.reload();
                        layer.msg('已删除!',{icon:1,time:1000});

                    }else{
                        layer.msg('删除失败!',{icon:2,time:1000});
                    }

                }
            });

        });
    }

    //列表搜索
    form.on('submit(provinceSearch)', function (data) {
        var userName = data.field.userName;
        var email = data.field.email;
        var phone = data.field.phone;
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        laydate = layui.laydate;//日期插件
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层
        form = layui.form();//弹出层
        //  1)分页插件
        //以上模块根据需要引入
        table.render({
            elem: '#LAY-feedback-lst-manage'
            , url: basePath+'/javayh/alluser_admin?userName=' +userName +'&email='+email  +'&phone='+phone,
        });
        return false;

    });
</script>

</body>
</html>